package com.oracle.zebrafreelytraveling.ui.fragment;

import android.app.DialogFragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.oracle.zebrafreelytraveling.R;

/**
 * Created by yydcnjjw on 2017/8/5.
 */

public abstract class SlideBottomDialogFragment extends DialogFragment{

    public View mView;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NORMAL, R.style.slide_bottom_dialog_fragment);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);//默认不弹出软键盘
        getDialog().getWindow().setGravity(Gravity.BOTTOM);//Dialog处于页面的底部
        getDialog().setCanceledOnTouchOutside(true);//点击Dialog外围可以消除Dialog
        mView = inflater.inflate(getLayoutId(), container, false);
        return mView;
    }

    protected abstract int getLayoutId();

    @Override
    public void onResume() {
        super.onResume();
        DisplayMetrics metric = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(metric);
        getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);

    }

    @Override
    public void show(FragmentManager manager, String tag) {
        if (manager.findFragmentByTag(tag) == null){
            super.show(manager, tag);
        }
    }
}
